package util;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class DoubleUtil {
    public static void main(String[] args) {
        System.out.println(compare(6, 5));
    }

    //品牌商品分计算公式
    public static double getPoiUpcScore(int upcNum) {
        if (upcNum >= 18) {
            return 100;
        } else if (upcNum >= 10) {
            return 100 - divide(multiply(18 - upcNum, 20), 8);
        } else if (upcNum >= 4) {
            return 80 - divide(multiply(10 - upcNum, 20), 6);
        } else if (upcNum > 0) {
            return 60 - divide(multiply(4 - upcNum, 60), 4);
        } else {
            return 0;
        }
    }

    /**
     * 两个double类型数值做乘法
     */
    public static double multiply(double value1, double value2) {
        BigDecimal b1 = new BigDecimal(Double.toString(value1));
        BigDecimal b2 = new BigDecimal(Double.toString(value2));
        return b1.multiply(b2).setScale(2, RoundingMode.HALF_UP).doubleValue();
    }

    /**
     * 两个double类型数值做除法
     */
    public static double divide(double price1, double price2) {
        return BigDecimal.valueOf(price1).divide(BigDecimal.valueOf(price2), 2, RoundingMode.HALF_UP).doubleValue();
    }

    /**
     * 两个double类型数值做比较
     */
    public static int compare(double value1, double value2) {
        BigDecimal b1 = new BigDecimal(Double.toString(value1));
        BigDecimal b2 = new BigDecimal(Double.toString(value2));
        return b1.compareTo(b2);
    }
}
